#!/bin/sh

git pull

kill $(ps --ppid 1 | grep 'chromedriver' | awk "{ print \$1 }") 2
kill $(ps --ppid 1 | grep 'chrome' | awk "{ print \$1 }") 2


NAME=main.py
#echo $NAME
ID=`ps -ef | grep "$NAME" | grep -v "$0" | grep -v "grep" | awk '{print $2}'`
#echo $ID
echo "---------------"
for id in $ID
do
kill -9 $id
echo "killed main.py $id"
done
echo "---------------"

NAME=push_manager.py
#echo $NAME
ID=`ps -ef | grep "$NAME" | grep -v "$0" | grep -v "grep" | awk '{print $2}'`
#echo $ID
echo "---------------"
for id in $ID
do
kill -9 $id
echo "killed push_manager.py $id"
done
echo "---------------"

if [ "$1" = "1" ]
then
nohup python3 -u main.py >& weibo_dynamic_push.log &
nohup python3 -u twitter_main.py >& twitter_dynamic_push.log &
nohup python3 -u push_manager.py >& weibo_push_manager.log &
echo "重启成功"
fi

